package org.shoukaiseki.aliyun.sms.config;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.annotation.Resource;

/**
 * org.shoukaiseki.aliyun.sms.config.AliyunSmsConfiguration
 * <br>
 *
 * @author shoukaiseki ブログ http://www.shoukaiseki.top/<br> E-メール jiang28555@Gmail.com<br>
 * @date 2020-12-05 17:33:30<br>
 */
@Configuration
//@EnableConfigurationProperties(AliyunSmsConfigProperties.class)
public class AliyunSmsConfiguration {


    /**
     * 设置为主要，master才会是默认的配置
     * @return
     */
    @Primary
    @Bean
    public AliyunSmsConfigProperties aliyunSmsConfigProperties(){
        return new AliyunSmsConfigProperties();
    }

    private static final String ALIYUN_SMS_ACS_CLIENT_BEAN_NAME = "aliyunSmsAcsClient";

    @Bean(name=ALIYUN_SMS_ACS_CLIENT_BEAN_NAME)
    public IAcsClient aliyunSmsAcsClient(){
        AliyunSmsConfigProperties aliyunSmsConfigProperties = aliyunSmsConfigProperties();
        DefaultProfile profile = DefaultProfile.getProfile(aliyunSmsConfigProperties.getRegionId(), aliyunSmsConfigProperties.getAccessKeyId(), aliyunSmsConfigProperties.getSecretAccessKey());
        IAcsClient client = new DefaultAcsClient(profile);
        return client;
    }

}
